﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using DTO;

namespace DAO
{
   public class BanHang_TVDAO
    {
       // Load cmb Thanhvien
       public List<ThanhVienDTO> LayBangThanhVien()
       {
           SqlConnection conn = DataProvider.ConnectDB();
           string sqlStr = "Select * from ThanhVien";
           SqlCommand cmd = new SqlCommand(sqlStr, conn);
           SqlDataReader da = cmd.ExecuteReader();
           List<ThanhVienDTO> kq = new List<ThanhVienDTO>();
           while (da.Read())
           {
               ThanhVienDTO temp = new ThanhVienDTO();
               temp.MaTV = da["MaTV"].ToString();
               temp.TenTV = da["TenTV"].ToString();
               temp.NgaySinh = DateTime.Parse(da["NgaySinh"].ToString());
               temp.DiaChi = da["DiaChi"].ToString();
               temp.SDT = da["SDT"].ToString();
               temp.CV = int.Parse(da["CV"].ToString());
               temp.TienNo = float.Parse(da["TienNo"].ToString());
               kq.Add(temp);
           }
           return kq;
       }

       // Load cmb Loaidonhang
       public List<LoaiDHDTO> LayBangLoaiDH()
       {
           SqlConnection conn = DataProvider.ConnectDB();
           string sqlStr = "select * from LoaiDH";
           SqlCommand cmd = new SqlCommand(sqlStr, conn);
           SqlDataReader da = cmd.ExecuteReader();
           List<LoaiDHDTO> kq = new List<LoaiDHDTO>();
           while (da.Read())
           {
               LoaiDHDTO temp = new LoaiDHDTO();
               temp.MaLoaiDH = da["MaLoaiDH"].ToString();
               temp.TenLoaiDH = da["TenLoaiDH"].ToString();
               kq.Add(temp);
           }
           return kq;
       }

       // Load  cmd Timkiem
       public List<DonBanHangDTO> LayBangDonBanHang()
       {
           SqlConnection conn = DataProvider.ConnectDB();
           string sqlStr = "select * from DonBanHang";
           SqlCommand cmd = new SqlCommand(sqlStr, conn);
           SqlDataReader da = cmd.ExecuteReader();
           List<DonBanHangDTO> kq = new List<DonBanHangDTO>();
           while (da.Read())
           {
               DonBanHangDTO temp = new DonBanHangDTO();
               temp.MaDBH = da["MaDBH"].ToString();
               temp.NgayBan = DateTime.Parse(da["NgayBan"].ToString());
               temp.MaNV = da["MaNV"].ToString();
               temp.MaTV = da["MaTV"].ToString();
               temp.DiaChiKH = da["DiaChiKH"].ToString();
               temp.TongTien = float.Parse(da["TongTien"].ToString());
               temp.LoaiDH = da["LoaiDH"].ToString();
               temp.TinhTrangDH = int.Parse(da["TinhTrangDH"].ToString());
               temp.PhuongThucTT = int.Parse(da["PhuongThucTT"].ToString());
               temp.GhiChu = da["GhiChu"].ToString();
               temp.TenKH = da["TenKH"].ToString();
               kq.Add(temp);
           }
           return kq;
       }
    }
}
